<?php

class ImageModel extends AbstractModel
{

    protected function _init()
    {
	
    }
    
    public function getImage($thumb = false)
    {
	$path = $this->getImagePath($thumb);
	if (!$path) {
	    return Yii::app()->params['noRecordImage'];
	}
	return $path;
    }

    public function getImagePath($thumb = false, $absolute = false)
    {
	if (!$this->getId()) {
	    return false;
	}
	$path = array(
	    $absolute ? Yii::app()->params['uploadDir'] : Yii::app()->params['uploadDirectory'],
	    $this->path,
	    $thumb ? 'thumb' : 'origin',
	    $thumb ? $this->thumb_name : $this->real_name
	);
	$path = implode(DIRECTORY_SEPARATOR, $path);
	$absPath = $absolute ? $path : Yii::getPathOfAlias('webroot') . $path;
	if (!file_exists($absPath)) {
	    return false;
	}
	return $path;
    }    

}